package com.ktjy.service.impl;

import com.ktjy.entity.Auction;
import com.ktjy.entity.Auctionrecord;
import com.ktjy.mapper.AuctionrecordMapper;
import com.ktjy.service.AuctionrecordService;
import com.ktjy.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-17
 * @Description:
 * @Version: 1.0
 */
public class AuctionrecordServiceImpl implements AuctionrecordService {
    @Override
    public List<Auctionrecord> selectAuctionrecordById(Long auctionid) {
        try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            try {
                AuctionrecordMapper mapper = sqlSession.getMapper(AuctionrecordMapper.class);
                List<Auctionrecord> auctionrecords = mapper.selectAuctionrecordById(auctionid);
                return auctionrecords;
            } catch (Exception e) {
                sqlSession.rollback(); // 回滚事务
                throw e;
            }
        }
    }

    @Override
    public boolean insertAuctionrecord(Auctionrecord auctionrecord) {
        try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            try {
                AuctionrecordMapper mapper = sqlSession.getMapper(AuctionrecordMapper.class);
                boolean result = mapper.insertAuctionrecord(auctionrecord) > 0;
                sqlSession.commit(); // 提交事务
                return result;
            } catch (Exception e) {
                sqlSession.rollback(); // 回滚事务
                throw e;
            }
        }
    }

    @Override
    public List<Auction> selectAuctionrecordAll(String startorEnd) {
        try (SqlSession sqlSession = MyBatisUtil.createSqlSession()) {
            try {
                AuctionrecordMapper mapper = sqlSession.getMapper(AuctionrecordMapper.class);
                List<Auction> auctions = mapper.selectAuctionrecordAll(startorEnd);
                return auctions;
            } catch (Exception e) {
                sqlSession.rollback(); // 回滚事务
                throw e;
            }
        }
    }
}
